function ccR_Rogue_UseStealth()
	if not ccrPlayerHasBuff(STEALTH)
	and not ccrPlayerIsInStealth()
	and ccrSpellIsReady(STEALTH)
	and not ccrPlayerIsCastingOrChanneling()										-- Casting or channeling
	and IsResting() == nil															-- Resting
	and UnitOnTaxi("player") == nil													-- On a Taxi
	and not IsMounted()																-- Mounted
	and HasFullControl() == 1
	and not Player:IsDead()
	and UnitUsingVehicle("player") == nil
	and IsUsingVehicleControls() == nil
	--and ccrPlayerIsMoving()
	then
		if UnitExists("target") == nil
		and ccrSpellIsReady(STEALTH)
		then 
			-- No target so just stealth
			ccrCast(STEALTH)
			vLastAutoStealthAttempt = GetTime()
			return
		end
		-- Target check
		if Target
		and Target:Exists()
		then
			-- If friendly NPC, dont stealth unless out of talking range
			if (UnitIsFriend("player", "target") and Target:GetDistance() > 6)
			and ccrSpellIsReady(STEALTH)
			then
				vLastAutoStealthAttempt = GetTime()
				ccrCast(STEALTH)
				return
			end
			-- If my target's attackable, stealth
			if UnitCanAttack("player", "target") == 1
			and ccrSpellIsReady(STEALTH)
			then
				vLastAutoStealthAttempt = GetTime()
				ccrCast(STEALTH)
				return
			end
		end
	end
end

function ccR_Rogue_KeepBuffsUp()
	if ccRS.Rogue_KeepBuffsUp then
		if not RogueComboWatcher then
			RogueComboWatcher = CreateFrame("Frame");
			RogueComboWatcher:SetScript("OnUpdate", RogueComboWatcherOnUpdate)
		end
	else
		if RogueComboWatcher then
			RogueComboWatcher:SetScript("OnUpdate", nil)
		end
	end
end

local vTimeWaitedOnComboWatcher = 0
function RogueComboWatcherOnUpdate(self, elapsed)
	vTimeWaitedOnComboWatcher = vTimeWaitedOnComboWatcher + elapsed
	if Target
	and Target:Exists()
	and not Target:IsDead()
	and IsMounted() == nil
	and vTimeWaitedOnComboWatcher > 0.5
	then
		if vRogueComboPoints ~= nil
		and vRogueComboPoints > 0 then
			if vRogueComboPointsGUID == nil
			or vRogueComboPointsGUID ~= UnitGUID("target") then
				if ccrPlayerHasSpell(REDIRECT)
				and not ccrSpellIsOnCooldown(REDIRECT)
				and ccrSpellIsReady(REDIRECT)
				then
					ccrCast(REDIRECT)
				else
					if vRogueComboPointsGUID == nil
					or vRogueComboPointsGUID ~= UnitGUID("target") then
						if ccrPlayerHealth() < 100 then
							RF_Recuperate()
						else
							RF_SnD()
						end
					end
				end
			end
		end
		vRogueComboPointsGUID = UnitGUID("target")
		if UnitExists("target") == 1 then
			vRogueComboPoints = GetComboPoints("player", "target")
		end
		vTimeWaitedOnComboWatcher = 0
	end

	if vLastRogueComboCheck == nil
	or (GetTime()-vLastRogueComboCheck) > 1.0
	then
		if (
			not Target
			or 
				(
					Target:Exists()
					and Target:IsDead()
				)
			)
		and vRogueComboPoints ~= nil
		and vRogueComboPoints > 0
		then
			if ccrPlayerHealth() < 100 then
				RF_Recuperate()
			else
				RF_SnD()
			end
		end
		vLastRogueComboCheck = GetTime()
	end
end

function RF_Recuperate()
	if vRogueComboPoints == 1 then vDuration = 6 end;
	if vRogueComboPoints == 2 then vDuration = 12 end;
	if vRogueComboPoints == 3 then vDuration = 18 end;
	if vRogueComboPoints == 4 then vDuration = 24 end;
	if vRogueComboPoints == 5 then vDuration = 30 end;		
	if (
		ccrPlayerHasBuffRemaining(RECUPERATE, vDuration)
		or not ccrPlayerHasBuff(RECUPERATE)
		)
	and ccrSpellIsReady(RECUPERATE)
	then
		ccrCast(RECUPERATE)
		return
	end	
end

function RF_SnD()
	if vRogueComboPoints == 1 then vDuration = 12 end;
	if vRogueComboPoints == 2 then vDuration = 18 end;
	if vRogueComboPoints == 3 then vDuration = 24 end;
	if vRogueComboPoints == 4 then vDuration = 30 end;
	if vRogueComboPoints == 5 then vDuration = 36 end;
	if (
		ccrPlayerHasBuffRemaining(SLICE_AND_DICE, vDuration)
		or not ccrPlayerHasBuff(SLICE_AND_DICE)
		)
	and ccrSpellIsReady(SLICE_AND_DICE)
	then
		ccrCast(SLICE_AND_DICE)
		return
	end		
end